package cc.eddic.practice.concurrency.impl;

import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Stream;
import java.util.zip.GZIPInputStream;

@Slf4j
public class GzFileUtilImpl {
    public void readUtil(String folderName) {
        File file = new File(folderName);
        if (log.isDebugEnabled()) log.debug("读取文件夹：" + file.getPath());
        File[] files = file.listFiles();
        for(File f:files){
            String logPath = f.getName();
            if (logPath.substring(logPath.length() - 3, logPath.length()).equals(".gz")) {
                byte[] buffer = new byte[1024];
                try {
                    GZIPInputStream gzipIS = new GZIPInputStream(Files.newInputStream(Paths.get(f.getPath())));
                    String fileName = "D:\\索尼培训\\output";
                    int length;
                    FileOutputStream fos = new FileOutputStream(fileName+"\\"+f.getName().substring(0,f.getName().length()-3)+".txt");
                    while ((length= gzipIS.read(buffer)) > 0) {
                        fos.write(buffer, 0, length);

                    }
                    gzipIS.close();
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
